/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ar.edu.utn.frsf.cidisi.ginet.formalization.impl;

import ar.edu.utn.frsf.cidisi.ginet.formalization.FormalAssociation;
import ar.edu.utn.frsf.cidisi.ginet.formalization.FormalCBPLanguage;
import ar.edu.utn.frsf.cidisi.ginet.formalization.FormalElement;
import ar.edu.utn.frsf.cidisi.ginet.formalization.FormalizationPackage;
import ar.edu.utn.frsf.cidisi.ginet.formalization.MetamodelElement;
import ar.edu.utn.frsf.cidisi.ginet.formalization.RootElement;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.resource.Resource;

import org.eclipse.emf.ecore.util.EcoreEMap;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Formal CBP Language</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ar.edu.utn.frsf.cidisi.ginet.formalization.impl.FormalCBPLanguageImpl#getFormalizedElements <em>Formalized Elements</em>}</li>
 *   <li>{@link ar.edu.utn.frsf.cidisi.ginet.formalization.impl.FormalCBPLanguageImpl#getCbpMetamodel <em>Cbp Metamodel</em>}</li>
 *   <li>{@link ar.edu.utn.frsf.cidisi.ginet.formalization.impl.FormalCBPLanguageImpl#getAbstractGINet <em>Abstract GI Net</em>}</li>
 *   <li>{@link ar.edu.utn.frsf.cidisi.ginet.formalization.impl.FormalCBPLanguageImpl#getRootElement <em>Root Element</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class FormalCBPLanguageImpl extends EObjectImpl implements FormalCBPLanguage {
	/**
	 * The cached value of the '{@link #getFormalizedElements() <em>Formalized Elements</em>}' map.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFormalizedElements()
	 * @generated
	 * @ordered
	 */
	protected EMap<String, String> formalizedElements;

	/**
	 * The default value of the '{@link #getCbpMetamodel() <em>Cbp Metamodel</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCbpMetamodel()
	 * @generated
	 * @ordered
	 */
	protected static final Resource CBP_METAMODEL_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getCbpMetamodel() <em>Cbp Metamodel</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCbpMetamodel()
	 * @generated
	 * @ordered
	 */
	protected Resource cbpMetamodel = CBP_METAMODEL_EDEFAULT;

	/**
	 * The default value of the '{@link #getAbstractGINet() <em>Abstract GI Net</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAbstractGINet()
	 * @generated
	 * @ordered
	 */
	protected static final Resource ABSTRACT_GI_NET_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getAbstractGINet() <em>Abstract GI Net</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAbstractGINet()
	 * @generated
	 * @ordered
	 */
	protected Resource abstractGINet = ABSTRACT_GI_NET_EDEFAULT;

	/**
	 * The cached value of the '{@link #getRootElement() <em>Root Element</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRootElement()
	 * @generated
	 * @ordered
	 */
	protected RootElement rootElement;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected FormalCBPLanguageImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return FormalizationPackage.Literals.FORMAL_CBP_LANGUAGE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EMap<String, String> getFormalizedElements() {
		if (formalizedElements == null) {
			formalizedElements = new EcoreEMap<String,String>(FormalizationPackage.Literals.FORMAL_ASSOCIATION, FormalAssociationImpl.class, this, FormalizationPackage.FORMAL_CBP_LANGUAGE__FORMALIZED_ELEMENTS);
		}
		return formalizedElements;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Resource getCbpMetamodel() {
		return cbpMetamodel;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCbpMetamodel(Resource newCbpMetamodel) {
		Resource oldCbpMetamodel = cbpMetamodel;
		cbpMetamodel = newCbpMetamodel;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FormalizationPackage.FORMAL_CBP_LANGUAGE__CBP_METAMODEL, oldCbpMetamodel, cbpMetamodel));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Resource getAbstractGINet() {
		return abstractGINet;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAbstractGINet(Resource newAbstractGINet) {
		Resource oldAbstractGINet = abstractGINet;
		abstractGINet = newAbstractGINet;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FormalizationPackage.FORMAL_CBP_LANGUAGE__ABSTRACT_GI_NET, oldAbstractGINet, abstractGINet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public RootElement getRootElement() {
		if (rootElement != null && rootElement.eIsProxy()) {
			InternalEObject oldRootElement = (InternalEObject)rootElement;
			rootElement = (RootElement)eResolveProxy(oldRootElement);
			if (rootElement != oldRootElement) {
				InternalEObject newRootElement = (InternalEObject)rootElement;
				NotificationChain msgs = oldRootElement.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - FormalizationPackage.FORMAL_CBP_LANGUAGE__ROOT_ELEMENT, null, null);
				if (newRootElement.eInternalContainer() == null) {
					msgs = newRootElement.eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FormalizationPackage.FORMAL_CBP_LANGUAGE__ROOT_ELEMENT, null, msgs);
				}
				if (msgs != null) msgs.dispatch();
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, FormalizationPackage.FORMAL_CBP_LANGUAGE__ROOT_ELEMENT, oldRootElement, rootElement));
			}
		}
		return rootElement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public RootElement basicGetRootElement() {
		return rootElement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetRootElement(RootElement newRootElement, NotificationChain msgs) {
		RootElement oldRootElement = rootElement;
		rootElement = newRootElement;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, FormalizationPackage.FORMAL_CBP_LANGUAGE__ROOT_ELEMENT, oldRootElement, newRootElement);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRootElement(RootElement newRootElement) {
		if (newRootElement != rootElement) {
			NotificationChain msgs = null;
			if (rootElement != null)
				msgs = ((InternalEObject)rootElement).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - FormalizationPackage.FORMAL_CBP_LANGUAGE__ROOT_ELEMENT, null, msgs);
			if (newRootElement != null)
				msgs = ((InternalEObject)newRootElement).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FormalizationPackage.FORMAL_CBP_LANGUAGE__ROOT_ELEMENT, null, msgs);
			msgs = basicSetRootElement(newRootElement, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FormalizationPackage.FORMAL_CBP_LANGUAGE__ROOT_ELEMENT, newRootElement, newRootElement));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__FORMALIZED_ELEMENTS:
				return ((InternalEList<?>)getFormalizedElements()).basicRemove(otherEnd, msgs);
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__ROOT_ELEMENT:
				return basicSetRootElement(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__FORMALIZED_ELEMENTS:
				if (coreType) return getFormalizedElements();
				else return getFormalizedElements().map();
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__CBP_METAMODEL:
				return getCbpMetamodel();
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__ABSTRACT_GI_NET:
				return getAbstractGINet();
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__ROOT_ELEMENT:
				if (resolve) return getRootElement();
				return basicGetRootElement();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__FORMALIZED_ELEMENTS:
				((EStructuralFeature.Setting)getFormalizedElements()).set(newValue);
				return;
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__CBP_METAMODEL:
				setCbpMetamodel((Resource)newValue);
				return;
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__ABSTRACT_GI_NET:
				setAbstractGINet((Resource)newValue);
				return;
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__ROOT_ELEMENT:
				setRootElement((RootElement)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__FORMALIZED_ELEMENTS:
				getFormalizedElements().clear();
				return;
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__CBP_METAMODEL:
				setCbpMetamodel(CBP_METAMODEL_EDEFAULT);
				return;
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__ABSTRACT_GI_NET:
				setAbstractGINet(ABSTRACT_GI_NET_EDEFAULT);
				return;
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__ROOT_ELEMENT:
				setRootElement((RootElement)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__FORMALIZED_ELEMENTS:
				return formalizedElements != null && !formalizedElements.isEmpty();
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__CBP_METAMODEL:
				return CBP_METAMODEL_EDEFAULT == null ? cbpMetamodel != null : !CBP_METAMODEL_EDEFAULT.equals(cbpMetamodel);
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__ABSTRACT_GI_NET:
				return ABSTRACT_GI_NET_EDEFAULT == null ? abstractGINet != null : !ABSTRACT_GI_NET_EDEFAULT.equals(abstractGINet);
			case FormalizationPackage.FORMAL_CBP_LANGUAGE__ROOT_ELEMENT:
				return rootElement != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (cbpMetamodel: ");
		result.append(cbpMetamodel);
		result.append(", abstractGINet: ");
		result.append(abstractGINet);
		result.append(')');
		return result.toString();
	}

} //FormalCBPLanguageImpl
